package com.itboye.app.mian.activity;

import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.jmsfhz.R;
import com.itboye.jmsfhz.app.adapter.GongGaoAdapter;
import com.itboye.jmsfhz.app.adapter.NewsDongTaiAdapter;
import com.itboye.jmsfhz.data.presenter.Personnelpresenter;
import com.itboye.jmsfhz.widget.XListView;
import com.itboye.jmsfhz.widget.XListView.IXListViewListener;
import com.lfh.commentdemo.bean.AppModelNewsBean;

public class ActivityGongGao extends BaseActivity implements Observer,
		IXListViewListener {
	private AppModelNewsBean bean;
	private Personnelpresenter personnelpresenter;
	private String uid;
	private int page_num = 1;
	private int page_size = 5;
	XListView listviewgongao;
	GongGaoAdapter adapter;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_gonggao;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		showProgressDialog("数据加载中...", true);
		bean = new AppModelNewsBean();
		personnelpresenter = new Personnelpresenter(this);
		bean.setPage_num(page_num + "");
		bean.setPage_size(page_size + "");
		bean.setCate("6054");
		bean.setUid(uid);
		personnelpresenter.getInfo(bean);

		listviewgongao.setXListViewListener(this);
		/** 刷新后获取数据 **/
		// listviewgongao.setPullLoadEnable(true);
		/** 刷新 **/
		listviewgongao.setPullRefreshEnable(true);

	}

	public void imgback(View view) {
		this.finish();
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub

		ResultEntity model = super.handlerError(data);

		if (model.getEventType() == personnelpresenter.HeZuoSuccessEvent) {
			bean = (AppModelNewsBean) model.getData();
			adapter = new GongGaoAdapter(this, bean);
			listviewgongao.setAdapter(adapter);
			System.out.println(">>>>>>>>>>>>>>>>>>" + model.getData());
		}
		try {
			/**
			 * 当数据加载出来后dialog则消失
			 */
			closeProgressDialog();
		} catch (Exception e) {

		}

		stopLoad();
	}

	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		page_num = 1;
		bean.setPage_num(page_num + "");
		// page_size=10;
		bean.setCate("6054");
		personnelpresenter.getInfo(bean);
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		page_num++;
		bean.setPage_num(page_num + "");
		page_size = 10;
		bean.setCate("6054");
		personnelpresenter.getInfo(bean);
	}

	public void stopLoad() {
		listviewgongao.stopLoadMore();
		listviewgongao.stopRefresh();
	}

}
